#!/bin/sh
PROJECT_NAME="cart-web"
AGENT_OPTS=""
if [ "$3" = "trace" ];then
	if [ -f "/opt/agent/pinpoint-bootstrap-1.7.1.jar" ];then
		AGENT_OPTS="-javaagent:/opt/agent/pinpoint-bootstrap-1.7.1.jar -Dpinpoint.agentId=$PROJECT_NAME -Dpinpoint.applicationName=$PROJECT_NAME"
	else
		echo 'Not found file:/opt/agent/pinpoint-bootstrap-1.7.1.jar'
	fi
fi
case "$1" in
 start)
  case "$2" in
   test | demo)
    java -Xms256m -Xmx256m $AGENT_OPTS -Dspring.profiles.active="$2"  -Dlog.level=info -Dlog.level.cass=trace -jar ./$PROJECT_NAME.jar >/dev/null 2>&1 &
   ;;
   prod)
    java -Xms256m -Xmx256m -Dspring.profiles.active="$2" -Dlog.level=warn -Dlog.level.cass=info -jar ./$PROJECT_NAME.jar >/dev/null 2>&1 &
   ;;
   *)
    printf 'append active profile: %s {test|demo|prod}\n' "$prog"
    exit 1
   ;;
  esac
 ;;
 stop)
  ps -ef|grep /$PROJECT_NAME.jar|awk '{print $2}'|while read pid
  do
    kill -15 $pid
  done
 ;;
 *)
  printf 'Usage: %s {start|stop}\n' "$prog"
  exit 1
 ;;
esac